import { defineConfig } from 'vite';
import solidPlugin from 'vite-plugin-solid';
import path from 'node:path';

const m = process.argv[4];

export default defineConfig({
  plugins: [solidPlugin()],
  build: {
    target: 'esnext',
    outDir: path.resolve(__dirname, `./dist/${m}`),
    lib: {
        entry: path.resolve(__dirname, m !== 'index' ? `./src/icons/${m}/${m}.tsx` : './src/index.tsx'),
        name: m
    },
    rollupOptions: {
      context: 'globalThis',
      preserveEntrySignatures: 'strict',
      external: ['solid-js','solid-js/web'],
      output: [
          {
              format: 'es',
              exports: 'named',
              sourcemap: false,
              entryFileNames: m ? `${m}.min.esm.js` : 'cui-icons.min.esm.js',
              chunkFileNames: '[name].js',
              assetFileNames: '[name].[ext]',
              namespaceToStringTag: true,
              inlineDynamicImports: false,
              manualChunks: undefined,
          }
      ]
    }
  },
  resolve: {
    conditions: ['development', 'browser'],
    alias: {
      '@': path.resolve(__dirname, './src')
    }
  },
  server: {
    port: 5000,
    host: '0.0.0.0',
  },
  base: './'
});
